package cn.pzhuweb.controller;

import cn.pzhuweb.service.imp.CarServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Yancy xiao
 * @create 2022-12-14 23:36
 */
@WebServlet("/delete")
public class DeleteCarServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteCarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     * response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String sid = request.getParameter("id");
        int id = 0;
        try {
            id = Integer.parseInt(sid);
        } catch (Exception e) {
            request.getSession().setAttribute("error", "id不是数字");
            response.sendRedirect("error.jsp");
            return;
        }
        CarServiceImp carServiceImp = new CarServiceImp();
        carServiceImp.removeCarInfo(id);
        response.sendRedirect("showcar");
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     * response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}